package com.le.tester.imooc.oldfairy.coding.sorting;

/**
 * createTime：2023/5/23 10:35
 * description：冒泡排序
 */
public class BubbleSort implements IMutableSorter {
    @Override
    public void sort(int[] arr) {
        int length = arr.length - 1;
        for (int i = length; i >= 0; i--) {
            bubble(arr, 0, i + 1);
        }
    }

    private void bubble(int[] arr, int i, int j) {
        for (int k = 0; k < j - 1; k++) {
            if (arr[k] > arr[k + 1]) {
                Helper.swap(arr, k, k + 1);
            }
        }
    }
}
